﻿using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TeamService.Access
{    
    public class Project: IComparer,IComparable,IComparable<Project>,IEquatable<Project>,INotifyPropertyChanged
    {
        public Project()
        {
            Name = "未初始化";
            Description = "未初始化";
        }

        int _id;
        public int Id {
            get => _id;
            set {
                _id = value;
                Update(nameof(Id));
            }
        }

        string _name;
        public string Name {
            get => _name;
            set {
                _name = value;
                Update(nameof(Name));
            }
        }

        string _des;
        public string Description {
            get => _des;
            set {
                _des = value;
                Update(nameof(Description));
            }
        }

        ProjectState _state;
        public ProjectState State {
            get => _state;
            set {
                _state = value;
                Update(nameof(ProjectState));
            }
        }

        public ObservableCollection<Team> Teams { get; set; }



        public event PropertyChangedEventHandler PropertyChanged;
        void Update(string name) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));

        public override Int32 GetHashCode()
        {
            return Name.GetHashCode();
        }
        public Int32 Compare(Object x, Object y)
        {
            return string.Compare((x as Project).Name, (y as Project).Name);
        }

        public Int32 CompareTo(Object obj)
        {
            return Name.CompareTo(obj);
        }

        public Int32 CompareTo(Project other)
        {
            return Name.CompareTo(other.Name);
        }

        public Boolean Equals(Project other)
        {
            return Name.Equals(other.Name);
        }
    }
}
